﻿// Copyright (c)  MOKEYISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using System;

namespace NSQL.Expressions
{
    public interface IConstantIntegerExpression : IIntegerExpression, IConstantNumericExpression,
        IConstantExpression<int>
    {
    }

    public class IntegerExpression : ConstantExpression, IConstantIntegerExpression
    {
        public int Value { get; set; }
        private IntegerExpression(int value) : base(value) => Value = value;
        public override object ValueOf() => Value;

        public int Sign => Math.Sign(Value);
        public bool IsZero => Value == 0;
        public void MakeOpposite() => Value *= -1;
        public static implicit operator IntegerExpression(int val) => new IntegerExpression(val);
        public static implicit operator IntegerExpression(short val) => new IntegerExpression(val);
    }

    public static class IntegerExpressionExtensions
    {
        public static IntegerExpression AsExpression(this int self) => self;
        public static IntegerExpression ToExpression(this int self) => self;
    }
}